function addInd($scope, $route, CertusFormAjax, CertusJsonAjax, $location, $http, $cookies, $routeParams, $q, backlogPersonList, $compile){
    //初始化

    $scope.rzlcStepEntity = {};
    $scope.rzlcStepEntity.baseUser = {};
    $scope.rzlcStepEntity.baseUser.departmentUser={};
    $backlogPersonList = backlogPersonList;
    $$scope = $scope;


    //初始化 公司 名稱
    $scope.rzcomSelectIdSelect1 = [
        {departmentName:"赛特斯集团",departmentCode:"STSJT"},
        // {name:"赛特斯广东",code:"STSGD"},rzcomSelectIdSelect
        // {name:"赛特斯南京",code:"STSNJ"},
        // {name:"赛特斯北京",code:"STSBJ"},
        // {name:"赛特斯上海",code:"STSSH"},
        // {name:"浩方科技",code:"HFKJ"},
        // {name:"浩方信息",code:"HFXX"}
    ]

    $scope.sfzddnSelect = [
        {name:"待定",code:"不一定带"},
        {name:"带",code:"带"},
        {name:"不带",code:"不带"},
    ]

    CertusFormAjax.ajax("listIsTrueDepartment",{"areaSelect":"XYGRZ"},function(res){
        if(res && res.data){
            $scope.dropdown1List = res.data;
        }
    })



    $scope.getBelongCompanyName = function(companyCode){
        CertusFormAjax.ajax("getRealDept",{"companyCode":companyCode},function(res){
            $scope.rzlcStepEntity.baseUser.belongCompanyName = res.data;
        })
    }

    CertusFormAjax.ajax("stscompSelectByAutho", {"areaSelect":"XYGRZ"}, function (res) {
        $scope.belongCompanyCodeSelect = res.data;
    })

    // $scope.belongCompanyCodeSelect = [
    //     {name:"赛特斯广东",code:"STSGD"},
    //     {name:"赛特斯南京",code:"STSNJ"},
    //     {name:"赛特斯北京",code:"STSBJ"},
    //     {name:"赛特斯上海",code:"STSSH"},
    //     {name:"浩方科技",code:"HFKJ"},
    //     {name:"浩方信息",code:"HFXX"}
    // ]
    //初始化 select
    $scope.rzlcStepEntity.baseUser.departmentUser.companyCode = 'STSJT';
    CertusFormAjax.ajax("deptedList",{companyCode:'STSJT'},function(res){
        $scope.departmentSelect =eval("("+res.data+")");
    })

    var userPinin;
    var userInterview;
    function isSamePinyin1(element){
        if(userPinin){
            userPinin = userPinin.toUpperCase();
        }
        var pinyin = "";
        var userName2 = "";
        var userName = "";
        if(element.pinyin){
            pinyin = element.pinyin.toUpperCase();
        }
        if(element.userName2){
            userName2 =  element.userName2.toUpperCase();
        }
        if(element.userName){
            userName = element.userName.toUpperCase();
        }

        //部门名称 联动 查询
        return pinyin.indexOf(userPinin) > -1 || userName2.indexOf(userPinin) > -1 || userName.indexOf(userPinin) > -1;
    }
    function isSamePinyin2(element){
        if(userInterview){
            userInterview = userInterview.toUpperCase();
        }
        var pinyin = "";
        var userName2 = "";
        var userName = "";
        if(element.pinyin){
            pinyin = element.pinyin.toUpperCase();
        }
        if(element.userName2){
            userName2 =  element.userName2.toUpperCase();
        }
        if(element.userName){
            userName = element.userName.toUpperCase();
        }

        //部门名称 联动 查询
        return pinyin.indexOf(userInterview) > -1 || userName2.indexOf(userInterview) > -1 || userName.indexOf(userInterview) > -1;
    }
    $scope.companyChange = function(a,i){
        debugger;
        var $rzcomSelect = $(".rzcomSelect");
        for(var ii in $scope["rzcomSelectIdSelect"+i]){
            if($scope["rzcomSelectIdSelect"+i][ii].departmentCode == $($("#rzcomSelectId"+i)).find("select").val()){
                $scope.rzlcStepEntity.departmentName = $scope["rzcomSelectIdSelect"+i][ii].departmentName
            }
        }
        // $scope.rzlcStepEntity.departmentName = $($("#rzcomSelectId"+i)).find("select");

        for(var j=i+1;j<$rzcomSelect.length+1;j++){
            $("#rzcomSelectId"+j).remove()
        }
        CertusFormAjax.ajax("subDepartment",{"superiorDepartCode":a},function(res){
            if(res.data){

                //判断 长度
                if(res.data.length && res.data.length > 0){


                    var id = "rzcomSelectId"+(i+1);
                    var idSelect = "rzcomSelectIdSelect"+(i+1);
                    $scope[idSelect] = res.data;

                    var str = "<div class='form-group customerForm rzcomSelect' id='"+ id +"'>\n" +
                        "                    <label class='col-sm-2 control-label'>L"+(i+1)+"</label>\n" +
                        "                        <div class='col-sm-10'>\n" +
                        "                        <select class='form-control'  ng-model='rzlcStepEntity" +
                        ".baseUser.belongCompanyCode"+(i+1)+"' ng-change='companyChange(rzlcStepEntity.baseUser.belongCompanyCode"+(i+1)+"," + (i+1) +")" +
                        "'>\n" +
                        "                        <option ng-repeat='cps in "+ idSelect+"' value='{{cps.departmentCode}}'>{{cps" +
                        ".departmentName}}</option>\n" +
                        "                    </select>\n" +
                        "                    </div>\n" +
                        "                    </div>";

                    var a2 = angular.element(str);
                    var newVar = $compile(a2)($scope);
                    angular.element("#rzcomSelectId"+i).after(newVar);
                    // angular.element(str);
                    //清空 后边 兄弟 节点
                    $rzcomSelect.length


                }
            }
        })
    }

    $scope.departmentChange = function(a){
        for(var xxxx in $scope.departmentSelect){
            if($scope.departmentSelect[xxxx].departmentCode == $scope.rzlcStepEntity.baseUser.departmentUser.departmentCode){
                $scope.rzlcStepEntity.baseUser.departmentUser.departmentName = $scope.departmentSelect[xxxx].departmentName;
            }
        }
    }

    //性别 select
    $scope.sexSelect = [
        {name:"男",code:"1"},
        {name:"女",code:"0"}
    ]

    //结婚情况
    $scope.marriageSelect = [
        {name:"已婚",code:"1"},
        {name:"未婚",code:"0"},
        {name:"已婚已育",code:"2"}
    ]
    //领导者 姓名变化
    $scope.$watch('rzlcStepEntity.baseUser.leaderName',function(principalName,oldName,b){
        if (principalName != "") {
            var userSelect = $scope.leaderNameSelect;
            if(principalName && principalName.indexOf(oldName) > -1 && b.leaderNameSelect && b.leaderNameSelect.length > 0){
                userPinin = principalName;
                b.leaderNameSelect = b.leaderNameSelect.filter(isSamePinyin1);
            }else{
                CertusFormAjax.ajax("relatedUser", {name: principalName}, function (res) {
                    if (res.data && res.data.length > 0) {
                        b.leaderNameSelect = res.data;
                    }
                });
            }

            if (b.leaderNameSelect && b.leaderNameSelect.length == 1) {
                var userSelect2 = userSelect[0];
                $scope.rzlcStepEntity.baseUser.leaderName = userSelect2.userName;
                $scope.rzlcStepEntity.baseUser.leaderId = userSelect2.userId;
            }
        }
    });



    //获得 员工 性别 名
    $scope.getSex = function(a){
        if(a == 1){
            return "男";
        }else{
            return "女";
        }
    }



    $scope.getMarriage = function(a){
        if(a == 1){
            return "已婚";
        }else if(a == 0 ){
            return "未婚";
        }else if(a == 2){
            return "已婚已育";
        }

        return "未婚";
    }

    //自动 筛选 面试 人
    $scope.$watch('rzlcStepEntity.interviewerManName',function(principalName,oldName,b){
        if (principalName != "") {
            var userSelect = $scope.interviewerNameSelect;
            if(principalName && principalName.indexOf(oldName) > -1 && b.interviewerNameSelect && b.interviewerNameSelect.length > 0){
                userInterview = principalName;
                b.interviewerNameSelect = b.interviewerNameSelect.filter(isSamePinyin2);
            }else{
                CertusFormAjax.ajax("relatedUser", {name: principalName}, function (res) {
                    if (res.data && res.data.length > 0) {
                        b.interviewerNameSelect = res.data;
                    }
                });
            }
            if (b.interviewerNameSelect && b.interviewerNameSelect.length == 1) {
                var userSelect2 = userSelect[0];
                $scope.rzlcStepEntity.interviewerManName = userSelect2.userName;
                $scope.rzlcStepEntity.interviewerManId = userSelect2.userId;
            }
        }
    });

    //添加 公司
    $scope.addUserSubmit = function(){
        if(!$scope.rzlcStepEntity.baseUser.leaderId){
            layer.msg("直接领导 填写不正确");
            return;
        }
        if($scope.rzlcStepEntity.interviewerManName){
            if(!$scope.rzlcStepEntity.interviewerManId){
                layer.msg("面试人员未填写");
                return;
            }
        }
        debugger
        if($scope.rzlcStepEntity.baseUser.willHaveEmail != 0 && $scope.rzlcStepEntity.baseUser.willHaveEmail != 1){
            layer.msg("请选择是否需要开通企业邮箱");
            return;
        }


        if($scope.rzlcStepEntity.baseUser.willHaveWeChat != 0 && $scope.rzlcStepEntity.baseUser.willHaveWeChat != 1){
            layer.msg("请选择是否需要开通企业微信");
            return;
        }

        if($scope.rzlcStepEntity.baseUser.willHaveBpm != 0 && $scope.rzlcStepEntity.baseUser.willHaveBpm != 1){
            layer.msg("请选择是否需要开通bpm");
            return;
        }
        //校验邮箱
        var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
        if(!myreg.test($scope.rzlcStepEntity.baseUser.personalEmail)){
            layer.msg("邮箱格式不正确 请检查")
            return false;
        }
        //获取 所选 department code
        var $rzcomSelect = $(".rzcomSelect");
        $scope.rzlcStepEntity.baseUser.departmentUser = {};
        if($rzcomSelect.length){
            for(var i = 0;i < $rzcomSelect.length;i++){
                var selectValue = $($rzcomSelect[i]).find("select").val();
                if(selectValue && !(selectValue.indexOf("undefined") > -1)){
                    $scope.rzlcStepEntity.baseUser.departmentUser.departmentCode = selectValue;
                }
            }
        }else{
            if($($rzcomSelect).find("select").val()){
                $scope.rzlcStepEntity.baseUser.departmentUser.departmentCode = $($rzcomSelect).find("select").val();
            }else{
                layer.msg("请选择入职部门");
                return;
            }
        }
        //检查 非空
        if(certusValidateNotnull()){
            CertusJsonAjax.ajax("rzlcStepStart",$scope.rzlcStepEntity,function(res){
                if(res.data == "success"){
                    findBacklogPersonHead(CertusFormAjax, "RZLC");
                    history.back();
                    return;
                }
                layer.msg("数据不全，请检查");
            })
        }
    }


}



function toInd($scope, $route, CertusFormAjax, CertusJsonAjax, $location, $http, $cookies, $routeParams, $q){
    var dataInit = CertusJsonAjax.dataInit("newUserList",{"areaSelect":"XYGRZ"},indColumns,'indContainer','indToolBarContainer');
    $$scope = $scope;
    $scope.userSelect = {"areaSelect":"XYGRZ"}

    CertusFormAjax.ajax("stscompSelectByAutho", {"areaSelect":"XYGRZ"}, function (res) {
        $scope.belongCompanyCodeSelect = res.data;
        $scope.companySelect = res.data;
    })

    CertusJsonAjax.initBaseAuthority($scope);
    // $scope.belongCompanyCodeSelect = [
    //     {name:"赛特斯广东",code:"STSGD"},
    //     {name:"赛特斯南京",code:"STSNJ"},
    //     {name:"赛特斯北京",code:"STSBJ"},
    //     {name:"赛特斯上海",code:"STSSH"},
    //     {name:"浩方科技",code:"HFKJ"},
    //     {name:"浩方信息",code:"HFXX"}
    // ]


    $scope.onPostSelect = [
        {name:"在职",code:"1"},
        {name:"待入职",code:"2"},
        {name:"未报到",code:"3"},
        {name:"离职",code:"4"},
        {name:"取消入职",code:"5"}
    ]


    $scope.searchNewUser = function(){
        dataInit.parameters = $scope.userSelect;
        dataInit.refresh(true);
    }


}

function printInd($scope, $route, CertusFormAjax, CertusJsonAjax, $location, $http, $cookies, $routeParams, $q){
    var userId = $routeParams.userId;
    $scope.getBelongCompanyName = function(companyCode){
        if(companyCode == "STSJT"){
            return "赛特斯集团";
        }else if(companyCode == "STSGD"){
            return "赛特斯广东";
        }else if(companyCode == "HFKJ"){
            return "浩方科技";
        }else if(companyCode == "HFXX"){
            return "浩方信息";
        }else if(companyCode == "STSBJ"){
            return "赛特斯北京";
        }else if(companyCode == "STSNJ"){
            return "赛特斯南京";
        }else if(companyCode == "STSSH"){
            return "赛特斯上海";
        }
    }
    CertusFormAjax.ajax("userDetail",{userId:userId},function(res){

        $scope.baseUser = res.data;
        // $scope.processs = res.data.processs;
    })
}

function infoInd($scope, $route, CertusFormAjax, CertusJsonAjax, $location, $http, $cookies, $routeParams, $q,$filter){
    var userId = $routeParams.userId;
    $$scope = $scope;

    $scope.getBelongCompanyName = function(companyCode){
        CertusFormAjax.ajax("getRealDept",{"companyCode":companyCode},function(res){
            $scope.rzlcStepEntity.baseUser.belongCompanyName = res.data;
        })
    }


    $scope.sfzddnSelect = [
        {name:"待定",code:"待定"},
        {name:"带",code:"带"},
        {name:"不带",code:"不带"},
    ]

    CertusFormAjax.ajax("userDetailById",{userId:userId},function(res){

        $scope.companySelect = [
            {name:"赛特斯集团",code:"STSJT"},
            {name:"赛特斯广东",code:"STSGD"},
            /*            {name:"赛特斯南京",code:"STSNJ"},
                        {name:"赛特斯北京",code:"STSBJ"},
                        {name:"赛特斯上海",code:"STSSH"},*/
            {name:"浩方科技",code:"HFKJ"},
            {name:"浩方信息",code:"HFXX"}
        ]
        $scope.getSex = function(a){
            if(a == 1){
                return "男";
            }else{
                return "女";
            }
        }

        $scope.departmentChange = function(a){
            for(var xxxx in $scope.departmentSelect){
                if($scope.departmentSelect[xxxx].departmentCode == $scope.rzlcStepEntity.baseUser.departmentUser.departmentCode){
                    $scope.rzlcStepEntity.baseUser.departmentUser.departmentName = $scope.departmentSelect[xxxx].departmentName;
                }
            }
        }

        //性别 select
        $scope.sexSelect = [
            {name:"男",code:"1"},
            {name:"女",code:"0"}
        ]

        //结婚情况
        $scope.marriageSelect = [
            {name:"已婚",code:"1"},
            {name:"未婚",code:"0"},
            {name:"已婚已育",code:"2"}
        ]

        $scope.getMarriage = function(a){
            if(a == 1){
                return "已婚";
            }else if(a == 0 ){
                return "未婚";
            }else if(a == 2){
                return "已婚已育";
            }

            return "未婚";
        }
        //初始化 数据

        $scope.rzlcStepEntity = res.data;
        $scope.rzlcStepEntity.baseUser.firstWorkTime = $scope.rzlcStepEntity.baseUser.firstWorkTime.split(" ")[0]
        $scope.rzlcStepEntity.baseUser.sex =  $scope.rzlcStepEntity.baseUser.sex+"";
        $scope.rzlcStepEntity.baseUser.isMarriage =  $scope.rzlcStepEntity.baseUser.isMarriage+"";
        $scope.processCCBXTrace = res.data.processs;

        CertusFormAjax.ajax("stscompSelectByAutho", {"areaSelect":"XYGRZ"}, function (res) {
            $scope.belongCompanyCodeSelect = res.data;
            $scope.companySelect = res.data;

            $scope.getBelongCompanyName($scope.rzlcStepEntity.baseUser.belongCompanyCode)

            for(var cs in $$scope.companySelect){
                if($scope.companySelect[cs].code == $scope.rzlcStepEntity.baseUser.belongCompanyCode){
                    $scope.rzlcStepEntity.baseUser.departmentUser.companyName = $scope.companySelect[cs].name;
                }
            }

        })


    })
}

function alterInd($scope, $route, CertusFormAjax, CertusJsonAjax, $location, $http, $cookies, $routeParams, $q){
    var userId = $routeParams.userId;


    $scope.belongCompanyCodeSelect = [
        {name:"赛特斯广东",code:"STSGD"},
        {name:"赛特斯南京",code:"STSNJ"},
        {name:"赛特斯北京",code:"STSBJ"},
        {name:"赛特斯上海",code:"STSSH"},
        {name:"浩方科技",code:"HFKJ"},
        {name:"浩方信息",code:"HFXX"}
    ]

    $scope.getBelongCompanyName = function(companyCode){
        if(companyCode == "STSJT"){
            return "赛特斯集团";
        }else if(companyCode == "STSGD"){
            return "赛特斯广东";
        }else if(companyCode == "HFKJ"){
            return "浩方科技";
        }else if(companyCode == "HFXX"){
            return "浩方信息";
        }else if(companyCode == "STSBJ"){
            return "赛特斯北京";
        }else if(companyCode == "STSNJ"){
            return "赛特斯南京";
        }else if(companyCode == "STSSH"){
            return "赛特斯上海";
        }
    }
    $$scope = $scope;
    //修改 方法
    $scope.alterReadyToWork = function(){
        CertusJsonAjax.ajax("alterReadyToWork",$scope.rzlcStepEntity.baseUser,function(res){
            if(res.data == "success"){
                history.back();
            }
        })
    }

    CertusFormAjax.ajax("userDetailById",{userId:userId},function(res){

        $scope.rzlcStepEntity = res.data;
        $scope.processCCBXTrace = res.data.processs;

        $scope.rzlcStepEntity.baseUser.sex =  $scope.rzlcStepEntity.baseUser.sex+"";
        $scope.rzlcStepEntity.baseUser.isMarriage =  $scope.rzlcStepEntity.baseUser.isMarriage+"";
        $scope.companySelect = [
            {name:"赛特斯集团",code:"STSJT"},
            {name:"赛特斯广东",code:"STSGD"},
            /*           {name:"赛特斯南京",code:"STSNJ"},
                       {name:"赛特斯北京",code:"STSBJ"},
                       {name:"赛特斯上海",code:"STSSH"},*/
            {name:"浩方科技",code:"HFKJ"},
            {name:"浩方信息",code:"HFXX"}
        ]

        $scope.getSex = function(a){
            if(a == 1){
                return "男";
            }else{
                return "女";
            }
        }

        $scope.departmentChange = function(a){
            for(var xxxx in $scope.departmentSelect){
                if($scope.departmentSelect[xxxx].departmentCode == $scope.rzlcStepEntity.baseUser.departmentUser.departmentCode){
                    $scope.rzlcStepEntity.baseUser.departmentUser.departmentName = $scope.departmentSelect[xxxx].departmentName;
                }
            }
        }

        //性别 select
        $scope.sexSelect = [
            {name:"男",code:"1"},
            {name:"女",code:"0"}
        ]

        //结婚情况
        $scope.marriageSelect = [
            {name:"已婚",code:"1"},
            {name:"未婚",code:"0"},
            {name:"已婚已育",code:"2"}
        ]

        //结婚情况
        $scope.marriageSelect = [
            {name:"已婚",code:"1"},
            {name:"未婚",code:"0"},
            {name:"已婚已育",code:"2"}
        ]

        $scope.getMarriage = function(a){
            if(a == 1){
                return "已婚";
            }else if(a == 0 ){
                return "未婚";
            }else if(a == 2){
                return "已婚已育";
            }

            return "未婚";
        }

        for(var cs in $$scope.companySelect){
            if($scope.companySelect[cs].code == $scope.rzlcStepEntity.baseUser.belongCompanyCode){
                $scope.rzlcStepEntity.baseUser.departmentUser.companyName = $scope.companySelect[cs].name;
            }
        }
    })
}


function dep1_name_change(a){
    debugger;
    $$scope.rzlcStepEntity.baseUser.dep1_name = $(a).html();
    $("#dropdownMenu1").html($$scope.rzlcStepEntity.baseUser.dep1_name);
}

function dep2_name_change(a){
    debugger;
    $$scope.rzlcStepEntity.baseUser.dep2_name = $(a).html();
    $("#dropdownMenu2").html($$scope.rzlcStepEntity.baseUser.dep2_name);
}
